import "package:ct_pa_majordomo/config/roomIcons.dart";
import "package:ct_pa_majordomo/config/theme_vars.dart";
import "package:ct_pa_majordomo/pages/device/electricity_meter/base/index.dart";
import "package:ct_pa_majordomo/pages/device/electricity_meter/ope_record/index.dart";
import "package:ct_pa_majordomo/pages/device/electricity_meter/setting/index.dart";
import "package:ct_pa_majordomo/pages/device/electricity_meter/use_record/index.dart";
import "package:ct_pa_majordomo/router/keys.dart";
import "package:ct_pa_majordomo/utils/stacker.dart";
import "package:ct_pa_majordomo/widgets/wrap_item.dart";
import "package:flutter/cupertino.dart";
import "package:flutter/material.dart";

class Config {
  final String name;
  final String path;
  final Object? arguments;
  final Widget icon;
  Config(this.name, this.path, this.arguments, this.icon, );
}

class Operation extends StatefulWidget {
  final Map info;
  const Operation({super.key, required this.info});


  @override
  State<StatefulWidget> createState() => _OperationState();

}

class _OperationState extends State<Operation> {

  List<Config> _config = [];

  @override
  void didUpdateWidget(covariant Operation oldWidget) {
    setState(() {
      _config = [
        Config("用电记录", Keys.DEVICE_ELECTRICITYMETER_USE_RECORD, widget.info["electricityMeterId"], const Icon(RoomIcons.use_electricity_record, size: 40, color: ThemeVars.colorPrimary,)),
        // Config("操作记录", Keys.DEVICE_ELECTRICITYMETER_OPE_RECORD, null, const Icon(RoomIcons.operation_record, size: 40, color: ThemeVars.colorPrimary,)),
        Config("基本信息", Keys.DEVICE_ELECTRICITYMETER_BASE, widget.info, const Icon(RoomIcons.base, size: 40, color: ThemeVars.colorPrimary,)),
        Config("设置", Keys.DEVICE_ELECTRICITYMETER_SETTING, widget.info, const Icon(Icons.settings, size: 40, color: ThemeVars.colorPrimary,)),
      ];
    });
    super.didUpdateWidget(oldWidget);
  }


  @override
  Widget build(BuildContext context) {
    return DecoratedBox(
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(12),
          boxShadow: const [ThemeVars.boxShadow],
          color: Colors.white,
        ),
        child: Container(
          padding: const EdgeInsets.symmetric(vertical: 16),
          child: Wrap(
            children: _config.map((ele) {
              return GestureDetector(
                behavior: HitTestBehavior.opaque,
                onTap: () {
                  Stacker.pushNamed(ele.path, arguments: ele.arguments);
                },
                child: WrapItem(
                    span: 4,
                    child: Container(
                      padding: const EdgeInsets.symmetric(vertical: 16),
                      child: Center(
                        child: Column(
                          children: [
                            SizedBox(
                              width: 40,
                              height: 40,
                              child: ele.icon,
                            ),
                            const SizedBox(height: 10,),
                            Text(ele.name, style: const TextStyle(fontWeight: FontWeight.w600),),
                          ],
                        ),
                      ),
                    )
                ),
              );
            }).toList(),
          ),
        )
    );
  }

}
